function showerror(msg,url){
	layer.open({
		content: msg,
		style: 'background-color:#ef4f4f; color:#fff; border:none;text-align:center;font-size:16px;',
		time: 3,
		end:function(){
			if(url){
				location.href = url;
			}
		}
	});
}

function showsuccess(msg,url){
	layer.open({
		content: msg,
		style: 'background-color:#04be02; color:#fff; border:none;text-align:center;font-size:16px;',
		time: 2,
		end:function(){
			if(url){
				location.href = url;
			}
		}
	});
}

/*
 * 操作确认
 */
function comfirm(url,title){
    layer.open({
        content: title,
        btn: ['确定', '取消'],
        yes: function(index){
        	AjaxUrl(url);
            layer.close(index);
        }
    });
}

//ajax静默请求
function ajax_url(url,data){
	if(!data){
		var type = "GET";
		var data = '';
	}else{
		var type = "POST";
	}
	
	$.ajax({
		url : url,
		type : type,
		data : data,
		dataType : 'json',
		success : function(data) {
			//alert(data.msg);
			console.log(data);
		},
       error: function() {
    	   console.log('error');
    	  // alert('error');
       }
       
	});
}



function AjaxUrl(url){
	$.ajax({
		url : url,
		type : "GET",
		dataType : 'json',
	//	async : false,
		success : function(data) {
			//关闭正在加载
			 layer.closeAll();//关闭所有
			if(data.url){
				var urls = data.url;
			}else{
				var urls = '';
			}

			if(data.ret == 0){
				// 成功
				showsuccess(data.msg,urls);
			}else{
				// 失败
				showerror(data.msg,urls);
			}
		},
		beforeSend:function(){
			//正在加载
			layer.open({
		        type: 2,
		        shade: true,
		        shadeClose: false,
		    });
			
       },
       error: function() {
		   //关闭正在加载
    	   layer.closeAll();//关闭所有
		   showerror("网络错误,请重试");
       }
       
	});
}

//表单异步提交
function AjaxFormSubmit(formId, post) {
	// 表单不存在 则直接返回
	if(!formId){
		var formId = "form";
	}
	if ($('#' + formId).length == 0) {
		return false;
	}
	var action = $('#' + formId).attr('action');
	if (!action) {
		action = location.href;
	}
	if (!post) {
		post = 'post';
	}
	$.ajax({
		url : action,
		type : post,
		data : $('#' + formId).serialize(),
		dataType : 'json',
	//	async : false,
		success : function(data) {
			//关闭正在加载
			layer.closeAll();//关闭所有
			
			if(data.url){
				var urls = data.url;
			}else{
				var urls = '';
			}

			if(data.ret == 0){
				// 成功
				showsuccess(data.msg,urls);
			}else{
				// 失败
				showerror(data.msg,urls);
			}
		},
		beforeSend:function(){
			//正在加载
			layer.open({
		        type: 2,
		        shade: true,
		        shadeClose: false,
		    });
			
       },
       error: function() {
		   //关闭正在加载
    	   layer.closeAll();//关闭所有
		   showerror("网络错误,请重试");
       }
       
	});
}

function gourl(url) {
	window.location.href = url;
}

// 消息弹窗 可加回调方法


// 是否是手机号码
function isMobile(mobile) {
	return /^1[3|4|5|8|7][0-9]\d{8}$/i.test(mobile);
}

//货币格式验证 by xiaobei
function checkCurrency(str){
   var re = /^\d+.?\d{0,2}$/;
   if(re.test(str)){
       return true;//通过
   }
   return false;
}


/*
 * 获取手机型号
 */
function getPhoneType() {
	// 正则,忽略大小写
	var pattern_phone = new RegExp("iphone", "i");
	var pattern_android = new RegExp("android", "i");
	var userAgent = navigator.userAgent.toLowerCase();
	var isAndroid = pattern_android.test(userAgent);
	var isIphone = pattern_phone.test(userAgent);
	var phoneType = "其他";
	
	if (isAndroid) {
		var zh_cnIndex = userAgent.indexOf("-");
		var spaceIndex = userAgent.indexOf("build", zh_cnIndex + 4);
		var fullResult = userAgent.substring(zh_cnIndex, spaceIndex);
		phoneType = fullResult.split(";")[1];
	} else if (isIphone) {
		// 6 w=375, 6plus w=414 ,5s w=320 ,5 w=320
		var wigth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
		if (wigth > 400) {
			phoneType = "iphone6 plus";
		} else if (wigth > 370) {
			phoneType = "iphone6";
		} else if (wigth > 315) {
			phoneType = "iphone5s";
		} else {
			phoneType = "iphone 4s";
		}
	} else {
		//TODO
	}

	return phoneType;
}